package com.xiaomazi.servicebase.exceptionhandler;

import com.xiaomazi.common.utils.R;
import com.xiaomazi.servicebase.exception.LLXYException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @program: llxy-parent
 * @description: 全局异常处理
 * @author: 小马子
 * @create: 2023-02-08 23:26
 **/
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public R error(Exception e){
        log.error(e.getMessage());
        e.printStackTrace();
        return R.error().message("执行了全局异常处理..");
    }


    @ExceptionHandler(LLXYException.class)
    public R error(LLXYException e){
        log.error(e.getMessage());
        e.printStackTrace();
        return R.error().code(e.getCode()).message(e.getMsg());
    }
}
